import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
public class DrawGraph {
	public static void main(String[] args){
		BufferedImage bi=new BufferedImage(1000,1000,BufferedImage.SCALE_SMOOTH);//create image buffer.
		Graphics2D g=bi.createGraphics();//get g.
		g.setColor(new Color(255, 255, 255));//set paint color to WHITE.
		g.fillRect(0, 0, 1000, 1000);//fill backgroud.
		g.setColor(new Color(0,0,255,100));
		File f=new File("D:/CUDA_graph_bundler.jpeg");//FIXME

		 //read data and draw.
		 try {
		 FileReader fr=new FileReader("D:/CUDA_graph_bundler.txt");//FIXME
		 BufferedReader br=new BufferedReader(fr);
		
		 System.out.println("working...");
		 String line;
		 String field[]=new String [44];
		 int x1,y1,x2,y2;
		 int j;
		 while(((line=br.readLine())!=null)){
		 field=line.split(",");
		 
		 for(j=0;j+3<13;j+=2){
			 x1=(int)Double.parseDouble(field[j]);
			 y1=(int)Double.parseDouble(field[j+1]);
			 x2=(int)Double.parseDouble(field[j+2]);
			 y2=(int)Double.parseDouble(field[j+3]);
			 g.drawLine(x1, y1, x2, y2);
			 }
		// g.setColor(new Color(0,200,0,80));
		 for(;j+3<26;j+=2){
			 x1=(int)Double.parseDouble(field[j]);
			 y1=(int)Double.parseDouble(field[j+1]);
			 x2=(int)Double.parseDouble(field[j+2]);
			 y2=(int)Double.parseDouble(field[j+3]);
			 g.drawLine(x1, y1, x2, y2);
			 }
		 }
		 br.close();
		 fr.close();
		 System.out.println("done!\n");
		 }catch (Exception e) {
		 e.printStackTrace();
		 }
		 
		 //write to file.
		try {
			ImageIO.write(bi, "jpeg", f);
			f.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
